﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using Raider.WinForms.Actions.Properties;
using Raider.WinForms.Actions.Utils;

namespace Raider.WinForms.Actions.Standard
{
    /// <summary>
    /// Inserts a text from the clipboard (if any).
    /// </summary>
    /// <remarks>
    /// Supports all controls derived from <see cref="TextBoxBase"/>.
    /// </remarks>
    [Description("Inserts a text from the clipboard.\nSupports all controls derived from TextBoxBase.")]
    public class PasteAction : EditAction
    {
        public PasteAction()
            : base(Resources.Paste, Keys.Control | Keys.V, Resources.PasteImage)
        {
        }

        protected override void OnExecute(ExecuteEventArgs args)
        {
            base.OnExecute(args);

            var textBox = lastFocusedControl as TextBoxBase;
            if (textBox != null) textBox.Paste();
        }

        protected override void OnUpdate(UpdateEventArgs args)
        {
            base.OnUpdate(args);

            var textBox = lastFocusedControl as TextBoxBase;
            Enabled = textBox != null && !textBox.ReadOnly && Clipboard.ContainsText();
        }
    }
}
